<template>
    <div class="modal fade" id="addSaleModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          	<div class="modal-header">
            	<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            	<h4 class="modal-title" id="myModalLabel"> 销售状态变更</h4>
          	</div>
          	<div class="modal-body">
          	 	<div class="form-horizontal">
          	 		<div class="form-group">
	                  <label class="col-md-4 col-sm-2 control-label"><span class="required">*</span>销售状态：</label>
						<div class="col-md-8 col-sm-10">
							<select class="form-control" v-model="sale.saleStatus">
								<option value="0">待售</option>
								<option value="1">在售</option>
								<option value="2">售罄</option>
								<option value="3" v-if="shelves">下架</option>
							</select>
						</div>
	                </div>
	            </div>
          	</div>
          	<div class="modal-footer">
            	<!--<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>-->
            	<button type="button" class="btn checkedBtn" v-show="btnShow" @click="saveSale">确定</button>
          	</div>
        </div>
      </div>
    </div>
</template>

<script>
	export default{
		//接收父组件的绑定值
		props: ["saleModal"],
		data() {
			return {
				//机构信息对象
				sale: {
					saleStatus: '1'
				},
				btnShow: true,
                shelves:true
			}
		},
		watch: {
			//监听父组件绑定值是否改变
			saleModal: {
				handler: function(val, oldVal){
					this.init();
				},
				//深层监听，当位对象时，若设为true，属性变更时即可触发，若为false，属性无法监听到
				deep: true
			}
		},
		methods: {
			init(){
				this.sale.saleStatus = this.saleModal.saleStatus;
				if(3 == this.sale.saleStatus){
                    this.shelves = false;
				}else{
                    this.shelves = true;
				}
			},saveSale() {
				var _self = this;
				var body={};
				body.params = {
					id: this.saleModal.premisesId,
					saleStatus: _self.sale.saleStatus
				};
				var url = this.utilHelper.apiUrl+'/api/changePremisesSaleStatus';
				_self.$http.post(url, body).then((response)=>{
					var resData = response.body.resData ;
					if(resData.result == "1"){
                		layer.msg("变更成功");
                		$('#addSaleModal').modal('hide');
						//子组件向父组件传递信号: 调用父组件中对子组件的监听
						_self.$emit('saveAuditListener');
                	}else{
                		layer.msg("变更失败");
                	}
				},(response)=>{
					console.log(response);
					layer.msg("变更失败");
				});
			}
		}
	}
	
</script>